package cn.t17.appsys.dao;

import cn.t17.appsys.entity.AppInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * AppInfoMaper class
 *
 * @author Administrator
 * @date 2021/9/16
 */
public interface AppInfoMapper {
    @Select("<script>" +
            "select * from app_info" +
            "<where>" +
            "<if test='softwareName!=null'> softwareName like concat('%',#{softwareName},'%')</if>" +
            "<if test='status!=null'> and status = #{status}</if>" +
            "<if test='flatformId!=null'> and flatformId = #{flatformId}</if>" +
            "<if test='categoryLevel1!=null'> and categoryLevel1 = #{categoryLevel1}</if>" +
            "<if test='categoryLevel2!=null'> and categoryLevel2 = #{categoryLevel2}</if>" +
            "<if test='categoryLevel3!=null'> and categoryLevel3 = #{categoryLevel3}</if>" +
            "</where>" +
            "</script>")
    List<AppInfo> listBy(AppInfo info);

    @Select("<script>" +
            "select count(*) from app_info" +
            "<where>" +
            "<if test='softwareName!=null'> softwareName like concat('%',#{softwareName},'%')</if>" +
            "<if test='status!=null'> and status = #{status}</if>" +
            "<if test='flatformId!=null'> and flatformId = #{flatformId}</if>" +
            "<if test='categoryLevel1!=null'> and categoryLevel1 = #{categoryLevel1}</if>" +
            "<if test='categoryLevel2!=null'> and categoryLevel2 = #{categoryLevel2}</if>" +
            "<if test='categoryLevel3!=null'> and categoryLevel3 = #{categoryLevel3}</if>" +
            "</where>" +
            "</script>")
    Integer countBy(AppInfo info);

    @Select("<script>" +
            "select * from app_info" +
            "<where>" +
            "<if test='info.softwareName!=null'> softwareName like concat('%',#{info.softwareName},'%')</if>" +
            "<if test='info.status!=null'> and status = #{info.status}</if>" +
            "<if test='info.flatformId!=null'> and flatformId = #{info.flatformId}</if>" +
            "<if test='info.categoryLevel1!=null'> and categoryLevel1 = #{info.categoryLevel1}</if>" +
            "<if test='info.categoryLevel2!=null'> and categoryLevel2 = #{info.categoryLevel2}</if>" +
            "<if test='info.categoryLevel3!=null'> and categoryLevel3 = #{info.categoryLevel3}</if>" +
            "</where>" +
            " limit #{offset},#{pageSize} " +
            "</script>")
    List<AppInfo> listByPage(
            @Param("info") AppInfo info,
            @Param("offset") Integer offset,
            @Param("pageSize") Integer pageSize);

    @Delete("delete from app_info where id=#{id}")
    Integer deleteById(Integer id);

    @Update("update app_info set " +
            "categoryLevel1 = #{categoryLevel1}," +
            "categoryLevel2 = #{categoryLevel2}," +
            "categoryLevel3 = #{categoryLevel3}," +
            "flatformId = #{flatformId}," +
            "status = #{status}," +
            "supportROM = #{supportROM}," +
            "softwareSize = #{softwareSize}," +
            "softwareName = #{softwareName}" +
            " where id =  #{id}")
    Integer update(AppInfo info);

}
